<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="../static/images/favicon.ico" type="image/x-icon" />
      <link rel="stylesheet" href="statics/css/font.css">
      <link rel="stylesheet" href="statics/css/xadmin.css">
      <script src="statics/js/jquery.min.js"></script>
      <script src="statics/layui.js" charset="UTF-8"></script>
      <script type="text/javascript" src="statics/js/xadmins.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body style="text-align: center;margin:0 auto;">
    
    <div class="x-body" style="text-align: center;margin:0 auto;width: 600px"  >
    
        <form class="layui-form" style="width: 800px" enctype="multipart/form-data" method="post">
          <input type="hidden" name="id" value="${appsState.id}"/>
          <div class="layui-form-item" style="width: 800px">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>软件名称
              </label>
              <div class="layui-input-inline" style="width: 500px">
                  <input type="text" id="softwareName" name="softwareName"   value="${appsState.softwareName }"
                  autocomplete="off" class="layui-input" style="width: 500px">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>apk名称
              </label>
              <div class="layui-input-inline" style="width: 500px">
                  <input type="text" id="APKName" name="APKName"  value="${appsState.APKName }"
                  autocomplete="off" class="layui-input" style="width: 500px">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  <span class="x-red">*</span>支持ROM
              </label>
              <div class="layui-input-inline" style="width: 500px">
                  <input type="text" id="supportROM" name="supportROM"   value="${appsState.supportROM }"
                  autocomplete="off" class="layui-input" style="width: 500px">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>界面语言
              </label>
              <div class="layui-input-inline" style="width: 500px">
                  <input type="text" id="interfaceLanguage" name="interfaceLanguage" required=""  value="${appsState.interfaceLanguage }"
                  autocomplete="off" class="layui-input" style="width: 500px">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>软件大小
              </label>
              <div class="layui-input-inline" style="width: 500px">
                  <input type="text" id="softwareSize" name="softwareSize" required=""  value="${appsState.softwareSize }"
                  autocomplete="off" class="layui-input" style="width: 500px">
              </div>
          </div>
           <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>下载次数
              </label>
              <div class="layui-input-inline" style="width: 500px">
                  <input type="text" id="downloads" name="downloads"  value="${appsState.downloads }"
                  autocomplete="off" class="layui-input" style="width: 500px">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>所属平台
              </label>
              <div class="layui-input-inline" style="width: 500px">
                 <select name="flatformId" lay-filter="flatformId">
							
							<option value="1" selected="">${appsState.pv }</option>
					</select>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>一级分类
              </label>
              <div class="layui-input-inline" style="width: 500px">
                 <select name="categoryLevel1"
						lay-filter="cate1">
							<option value="0">-请选择-</option>
							<option value="1" <c:if test="${appsState.cate1=='全部应用'}">selected</c:if>>全部应用</option>
							<option value="2" <c:if test="${appsState.cate1=='全部游戏'}">selected</c:if>>全部游戏</option>
					</select>
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>二级分类
              </label>
              <div class="layui-input-inline" style="width: 500px">
                 <select name="categoryLevel2" lay-filter="cate2" id="cate2" >
							<option value="${appsState.id2}" selected="">${appsState.cate2}</option>
					</select>
              </div>
          </div>
           <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>三级分类
              </label>
              <div class="layui-input-inline" style="width: 500px">
                  <select name="categoryLevel3" lay-filter="aihao">
							<option value="${appsState.id3}" selected="">${appsState.cate3}</option>
					</select>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>app状态
              </label>
              <div class="layui-input-inline" style="width: 500px">
                  <select name="status" lay-filter="sta"">
							<option value="0">-请选择-</option>
							<option value="1"  <c:if test="${appsState.sv=='待审核'}">selected</c:if>>待审核</option>
							<option value="2"  <c:if test="${appsState.sv=='审核通过'}">selected</c:if>>审核通过</option>
							<option value="3"  <c:if test="${appsState.sv=='审核未通过'}">selected</c:if>>审核未通过</option>
							<option value="4"  <c:if test="${appsState.sv=='已上架'}">selected</c:if>>已上架</option>
							<option value="5"  <c:if test="${appsState.sv=='已下架'}">selected</c:if>>已下架</option>
					</select>
              </div>
          </div>
          <div class="layui-form-item layui-form-text">
              <label for="desc" class="layui-form-label">
                  应用简介
              </label>
              <div class="layui-input-block">
                  <textarea placeholder="请输入内容" id="desc" name="appInfo" class="layui-textarea" >${appsState.infos }</textarea>
              </div>
           
         </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <c:if test="${num=='审核未通过'}">
                <button  class="layui-btn" lay-filter="tijiao" lay-submit="">
                   保存并再次提交审核
              </button>
              </c:if>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  保存
              </button>
               <button  class="layui-btn" lay-filter="back" lay-submit="" >
                  重置
              </button>
          </div>
      </form>
    </div>
    <script>
    
        function reloads(){
        window.parent.location.reload();
        }
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
         
         form.on('select(cate1)',function(data){
         var cate1=$('select[name=categoryLevel1]').val();
         if(cate1==0){
           $('select[name=categoryLevel2]').html('<option value=0>-请选择-</option>');
           $('select[name=categoryLevel3]').html('<option value=0>-请选择-</option>');
           form.render();
         }else{
            $.ajax({
            url:"selectCategorys?parentId="+cate1,
            data:"parentId="+cate1,
            dataType:"JSON",
            type:"POST",
            success:function(data){
              if(data!=null){
                $('select[name=categoryLevel2]').html('');
                $('select[name=categoryLevel2]').html('<option value=0>-请选择-</option>');
                for(var i=0;i<data.length;i++){
                var option=$('<option value='+data[i].id+'>'+data[i].categoryName+'</option>');
                $('select[name=categoryLevel2]').append(option);
                //$('select[lay-filter=aihao]').append('你好');
                }
                form.render();
              }
            }
            });
         }
       });
       function loadss(){
       
       var cate2=$('select[name=categoryLevel2]').val();
         if(cate2=='0'){
         $("select[name='categoryLevel3']").html('<option value=0 >-请选择-</option>');
         form.render();
         }else{
            $.ajax({
            url:"selectCategorys?parentId="+cate2,
            data:"parentId="+cate2,
            dataType:"JSON",
            type:"POST",
            success:function(data){
              if(data!=null){
                $('select[name=categoryLevel3]').html('');
                $('select[name=categoryLevel3]').html('<option value=0>-请选择-</option>');
                for(var i=0;i<data.length;i++){
               // var option=$('<option value='+data[i].id+'>'+data[i].categoryName+'</option>');
                var option="";
                if(data[i].id==${appsState.id3}){
                option=$('<option value='+data[i].id+' selected >'+data[i].categoryName+'</option>');
                $('select[name=categoryLevel3]').append(option);
                }else{
                option=$('<option value='+data[i].id+' >'+data[i].categoryName+'</option>');
                }
                $('select[name=categoryLevel3]').append(option);
                //$('select[lay-filter=aihao]').append('你好');
                }
                form.render();
              }
            }
            
            });
         }
       }
       function loads(){
        var cate1=$('select[name=categoryLevel1]').val();
         if(cate1==0){
           $('select[name=categoryLevel2]').html('<option value=0>-请选择-</option>');
           $('select[name=categoryLevel3]').html('<option value=0>-请选择-</option>');
           form.render();
         }else{
            $.ajax({
            url:"selectCategorys?parentId="+cate1,
            data:"parentId="+cate1,
            dataType:"JSON",
            type:"POST",
            success:function(data){
              if(data!=null){
                $('select[name=categoryLevel2]').html('');
                $('select[name=categoryLevel2]').html('<option value=0>-请选择-</option>');
                for(var i=0;i<data.length;i++){
                var option="";
                if(data[i].id==${appsState.id2}){
                option=$('<option value='+data[i].id+' selected >'+data[i].categoryName+'</option>');
                $('select[name=categoryLevel2]').append(option);
                }else{
                option=$('<option value='+data[i].id+' >'+data[i].categoryName+'</option>');
                }
                $('select[name=categoryLevel2]').append(option);
                //$('select[lay-filter=aihao]').append('你好');
                }
                form.render();
              }
            }
            });
         }
       }
       loads();
       loadss();
       	$('select[name=categoryLevel2]').click(function(){
       	alert("dad");
       	})
	    form.on('click','select(cate2)',function(data){
	     var cate2=$('select[name=categoryLevel2]').val();
         if(cate2=='0'){
         $("select[name='categoryLevel3']").html('<option value=0 >-请选择-</option>');
         form.render();
         }else{
            $.ajax({
            url:"selectCategorys?parentId="+cate2,
            data:"parentId="+cate2,
            dataType:"JSON",
            type:"POST",
            success:function(data){
              if(data!=null){
                $('select[name=categoryLevel3]').html('');
                $('select[name=categoryLevel3]').html('<option value=0>-请选择-</option>');
                for(var i=0;i<data.length;i++){
                var option=$('<option value='+data[i].id+'>'+data[i].categoryName+'</option>');
                $('select[name=categoryLevel3]').append(option);
                //$('select[lay-filter=aihao]').append('你好');
                }
                form.render();
              }
            }
            
            });
         }
	    
	    });
		form.on('select(cate2)',function(data){
         		 
         var cate2=$('select[name=categoryLevel2]').val();
         if(cate2=='0'){
         $("select[name='categoryLevel3']").html('<option value=0 >-请选择-</option>');
         form.render();
         }else{
            $.ajax({
            url:"selectCategorys?parentId="+cate2,
            data:"parentId="+cate2,
            dataType:"JSON",
            type:"POST",
            success:function(data){
              if(data!=null){
                $('select[name=categoryLevel3]').html('');
                $('select[name=categoryLevel3]').html('<option value=0>-请选择-</option>');
                for(var i=0;i<data.length;i++){
                var option=$('<option value='+data[i].id+'>'+data[i].categoryName+'</option>');
                $('select[name=categoryLevel3]').append(option);
                //$('select[lay-filter=aihao]').append('你好');
                }
                form.render();
              }
            }
            
            });
         }
       
       });
        
         form.on('submit(add)',function(data){
          var index = layer.msg('数据保存中',{icon: 16,time:false,shade:0.5});
          var arr=$('form').serialize();
          /**
          var formData=new FormData();
          var softwareName=$("#softwareName").val();
          var softwareSize=$("#softwareSize").val();
          var APKName=$("#APKName").val();
          var supportROM=$("#supportROM").val();
          var downloads=$("#downloads").val();
          var cate1=$("select[name='cate1']").val();
          var cate2=$("select[name='cate2']").val();
          var cate3=$("select[name='cate3']").val();
          var desc=$("#desc").val();
          var fileName=document.getElementById("fileName").files[0];
          var states=$("select[name='states']").val();
          formData.append("softwareName",softwareName);
          formData.append("softwareSize",softwareSize);
          formData.append("APKName",APKName);
          formData.append("supportROM",supportROM);
          formData.append("downloads",downloads);
          formData.append("cate1",cate1);
          formData.append("cate2",cate2);
          formData.append("cate3",cate3);
          formData.append("desc",desc);
          formData.append("fileName",fileName);
          formData.append("states",states);
          **/
          $.ajax({
           url:"insertAppInfos",
           data:arr,
           dataType:"JSON",
           type:"POST",
           success:function(data){
             if(data=='ok'){
             var index1 = layer.msg('数据修改成功',{icon: 16,time:false,shade:0.5});
             layer.close(index);
             layer.close(index1);
             window.parent.location.href="admin-list";
             }else{
             var index2 = layer.msg('数据修改失败',{icon: 16,time:false,shade:0.5});
             layer.close(index2);
             }
           }
           
          });
          return false;
         })
          form.on('submit(tijiao)',function(data){
          var index = layer.msg('数据保存中',{icon: 16,time:false,shade:0.5});
          var arr=$('form').serialize();
          /**
          var formData=new FormData();
          var softwareName=$("#softwareName").val();
          var softwareSize=$("#softwareSize").val();
          var APKName=$("#APKName").val();
          var supportROM=$("#supportROM").val();
          var downloads=$("#downloads").val();
          var cate1=$("select[name='cate1']").val();
          var cate2=$("select[name='cate2']").val();
          var cate3=$("select[name='cate3']").val();
          var desc=$("#desc").val();
          var fileName=document.getElementById("fileName").files[0];
          var states=$("select[name='states']").val();
          formData.append("softwareName",softwareName);
          formData.append("softwareSize",softwareSize);
          formData.append("APKName",APKName);
          formData.append("supportROM",supportROM);
          formData.append("downloads",downloads);
          formData.append("cate1",cate1);
          formData.append("cate2",cate2);
          formData.append("cate3",cate3);
          formData.append("desc",desc);
          formData.append("fileName",fileName);
          formData.append("states",states);
          **/
          $.ajax({
           url:"insertAppInfoss",
           data:arr,
           dataType:"JSON",
           type:"POST",
           success:function(data){
             if(data=='ok'){
             var index1 = layer.msg('数据修改成功',{icon: 16,time:false,shade:0.5});
             layer.close(index);
             layer.close(index1);
             window.parent.location.href="admin-list";
             }else{
             var index2 = layer.msg('数据修改失败',{icon: 16,time:false,shade:0.5});
             layer.close(index2);
             }
           }
           
          });
          return false;
         })
        });
        
    </script>
    
    
  </body>

</html>